#ifndef _GAMEMANAGER_H_
#define _GAMEMANAGER_H_
#include<windows.h>
#include<d3d9.h>
#include<dinput.h>
#include"DAudio.h"
#define RESOLUTION_640_480_24 0
#define RESOLUTION_800_600_24 1	
#define RESOLUTION_1024_768_24 2

#define KEY_DOWN(code) ( IsKeyDown(code) )

#define KEYBOARD_BUFFER_SIZE	1024

class CGameManager
{
protected:
	LPDIRECT3D9 d3d;
	LPDIRECT3DDEVICE9 d3ddv;
	LPDIRECT3DSURFACE9 backbuffer;
	LPDIRECTINPUT8 dinput;
	LPDIRECTINPUTDEVICE8 Keyboard;
	BYTE KeyStates[256];
	DIDEVICEOBJECTDATA KeyEvents[KEYBOARD_BUFFER_SIZE];
	int Mode;
	int IsFullScreen;
	int ScreenWidth;
	int ScreenHeight;
	int Depth;
	DWORD timepassed;

	D3DFORMAT backbufferformat;
	HINSTANCE hInstance;
	HWND hWnd;
	LPWSTR Name;

	void SetScreenDimension(int Mode);
	static LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
	bool InitWindow();
	bool InitDirectX();
	bool InitKeyboard();
	void ProcessKeyBoard();
	int IsKeyDown(int KeyCode);
	void _RenderFrame();
	virtual void RenderFrame(LPDIRECT3DDEVICE9 d3ddv,int time);
	virtual void LoadResources(LPDIRECT3DDEVICE9 d3ddv);
	virtual void ProcessInput(LPDIRECT3DDEVICE9 d3ddv,int time);
	virtual void OnKeyDown(int KeyCode);
	virtual void OnKeyUp(int KeyCode);
public:
	int FrameRate;
	CGameManager(HINSTANCE hInstance, LPWSTR Name, int Mode,int isFullscreen, int FrameRate);
	~CGameManager();
	void Init();
	void Run();
};
#endif
